import { getHomeHotSuggests, getHomeCategories, getHomeHouselist } from '@/services/modules/home'
import { defineStore } from 'pinia'

const useHomeStore = defineStore('home', {
  state: () => ({
    hotSuggests: [],
    categories: [],
    houselist: [],
    page: 1,
  }),

  actions: {
    async getHotSuggestAction() {
      const res = await getHomeHotSuggests()
      this.hotSuggests = res.data
    },
    async getHomeCategoriesAction() {
      const res = await getHomeCategories()
      this.categories = res.data
    },
    async getHomeHouselistAction() {
      const res = await getHomeHouselist(this.page)
      this.houselist.push(...res.data)
      this.page++
    },
  },
})

export default useHomeStore
